| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { NextRequest, NextResponse } from 'next/server';
- import { ImportProcessor } from '@/app/lib/excel-import/import-processor';
- export async function POST(
- request: NextRequest,
- { params }: { params: { id: string } }
- ) {
- try {
- const importId = parseInt(params.id);
-
- if (isNaN(importId)) {
- return NextResponse.json(
- { success: false, error: 'Invalid import ID' },
- { status: 400 }
- );
- }
- // Initialize import processor
- const processor = new ImportProcessor();
-
- // Validate import before processing
- const validation = await processor.validateImport(importId);
- if (!validation.valid) {
- return NextResponse.json(
- { success: false, error: validation.errors.join(', ') },
- { status: 400 }
- );
- }
- // Start processing in background
- processor.processImport(importId).catch(error => {
- console.error('Import processing failed:', error);
- });
- return NextResponse.json({
- success: true,
- message: 'Import process started successfully',
- importId
- });
- } catch (error) {
- console.error('Error triggering import:', error);
- return NextResponse.json(
- { success: false, error: 'Failed to trigger import' },
- { status: 500 }
- );
- }
- }
|